<?php
namespace Home\Controller;
use Think\Controller;

class ExampleController extends Controller {
	//1.房间部分
	//创建房间
	//测试程序需要的curl start
	function curl_post($url='', $postdata='', $options=array()){
	    $ch = curl_init($url);
	    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	    curl_setopt($ch, CURLOPT_POST, 1);
	    curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
	    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
	    if (!empty($options)){
	        curl_setopt_array($ch, $options);
	    }
	    $data = curl_exec($ch);
	    curl_close($ch);
	    return $data;
	}
	function curl_get($url='', $options=array()){
	    $ch = curl_init($url);
	    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
	    if (!empty($options)){
	        curl_setopt_array($ch, $options);
	    }
	    $data = curl_exec($ch);
	    curl_close($ch);
	    return $data;
	}
	//测试程序需要的curl end
	//创建房间
	public function ex_roomcreate()
	{
		$url = "http://127.0.0.1/WebAPI/roomcreate/";
	    $postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id  authkey
	    $postdata['name'] = 'test'; //必填 房间名称
	    $postdata['chairmanpwd'] = '123456'; //必填 主席密码	必填，4=<长度<=20
	    $starttime = gmmktime(); //当前时间戳
	    $postdata['starttime'] = $starttime;  //必填 房间开始时间戳(精确到秒)
	    $postdata['endtime'] = $starttime+24*3600; //必填 房间结束时间(精确到秒)
	    $postdata['passwordrequired'] = 1; //选填 房间是否需要普通密码 0:否、1:是
	    $postdata['confuserpwd'] = '123456'; //房间普通用户密码 passwordrequired = 1 时必填(4=<长度<=10)
	    $postdata['isregisteruser'] = 1; //选填 必须注册用户参加 0:否、1:是
	    $postdata['allowsidelinuuser'] = 1; //选填 是否允许旁听用户参加 0:否、1:是
	    $postdata['sidelineuserpwd'] = '123456'; //旁听用户密码 4=<长度<=10 allowsidelineuser = 1 时必填
	    $postdata['confusernum'] = 10; //必填 普通用户数 
	    $postdata['sidelineusernum'] = 10; //选填 旁听用户数
	    $postdata['maxvideo'] = 1; //必填 最大视频数范围(0-24)
	    $postdata['roominfo'] = 'text'; //选填 房间描述
	    $postdata['videotype'] = 0; //选填 视频分辨率 0：流畅   1：标清 2：高清   3：超清
	    $postdata['roomlayout'] = 0; //选填 房间布局参数  0：综合布局 1:视频布局2:数据布局 
	    $postdata['roomusertyoe'] = '10'; //选填 参会的用户类型 '10'代表Flash用户，'01'代表Ipad用户
	    $postdata['call323'] = 1; //选填 呼叫323终端或者MCU  1:表示可以呼叫  0:不能
	    $postdata['callphone'] = 1; //选填 呼叫电话 1:表示可以呼叫  0:不能
	   
	    $postdata['visibleroom'] = 1; //选填 房间是否公开  0:不公开  1：公开

	    $resultdata = $this->curl_post($url,$postdata);
	    echo $resultdata;
	}
	//修改房间
	public function ex_roommodify()
	{
		$url = "http://127.0.0.1/WebAPI/roommodify/";
	    $postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
	    $postdata['serial'] = 277340593; //必填 房间号 
	    $postdata['roomname'] = 'text'; //必填 房间名 
	    $starttime = gmmktime(); //当前时间戳
	    $postdata['starttime'] = $starttime;  //必填 房间开始时间戳(精确到秒)
	    $postdata['endtime'] = $starttime+24*3600;//必填 房间结束时间(精确到秒)
	    $postdata['chairmanpwd'] = '123456'; //必填 主席密码	必填，4=<长度<=20
	    $postdata['passwordrequired'] = 1; //选填 房间是否需要普通密码 0:否、1:是
	    $postdata['confuserpwd'] = '123456'; //房间普通用户密码 passwordrequired = 1 时必填(4=<长度<=10)
	    $postdata['isregisteruser'] = 0; //选填 必须注册用户参加 0:否、1:是
	    $postdata['allowsidelineuser'] = 1; //选填 是否允许旁听用户参加 0:否、1:是
	    $postdata['sidelineuserpwd'] = '123456'; //旁听用户密码 allowsidelineuser = 1 时必填
	    $postdata['confusernum'] = 9; //必填 普通用户数 
	    $postdata['sidelineusernum'] = 9; //选填 旁听用户数
	    $postdata['maxvideo'] = 1; //必填 最大视频数
	    $postdata['roominfo'] = 'text'; //选填 房间描述
	    $postdata['videotype'] = 0; //选填 视频分辨率 0：流畅   1：标清 2：高清   3：超清
	    $postdata['roomlayout'] = 0; //选填 房间布局参数  0：综合布局 1:视频布局2:数据布局 
	    $postdata['roomusertype'] = '10'; //选填 参会的用户类型 '10'代表Flash用户，'01'代表Ipad用户
	    $postdata['call323'] = 1; //选填 呼叫323终端或者MCU  1:表示可以呼叫  0:不能
	    $postdata['callphone'] = 1; //选填 呼叫电话 1:表示可以呼叫  0:不能
	    $postdata['visibleroom'] = 1; //选填 房间是否公开  0:不公开  1：公开

	    $resultdata = $this->curl_post($url,$postdata);
	    echo($resultdata);
	}
	//删除房间
	public function ex_roomdelete()
	{
		$url = "http://127.0.0.1/WebAPI/roomdelete/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey 
		$postdata['serial'] = 277340593;//必填 房间号 

		$resultdata = $this->curl_post($url,$postdata);
		echo($resultdata);
	}
	//得到房间列表
	public function ex_getroomlist()
	{
		$url = "http://127.0.0.1/WebAPI/getroomlist/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填  企业id authkey
		$postdata['roomtype'] = 0; //选填 房间类型 0:表示全部房间 1：表示当前房间 2：未来房间 3：历史房间

		$resultdata = $this->curl_post($url,$postdata);
		echo($resultdata);
	}
	//得到某个时间范围内的房间
	public function ex_getroombytime()
	{
		$url = "http://127.0.0.1/WebAPI/getroombytime/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$starttime = gmmktime(); //当前时间戳
		$postdata['starttime'] = $starttime; //必填 房间开始时间戳(精确到秒)
		$postdata['endtime'] = $starttime+24*3600; //必填 房间结束时间戳(精确到秒)

		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}
	//得到某个房间的详细信息
	public function ex_getroom()
	{
		$url = "http://127.0.0.1/WebAPI/getroom/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['serial'] = 106046720; //必填 房间号
		
		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}
	//文档上传
	function ex_uploadfile()
    {
    	$url = "http://127.0.0.1/WebAPI/uploadfile/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['isopen'] = 1; //选填 是否是公开文档 0：表示非公开文档 1：表示公开文档公开文档表示公司的其他房间都可以关联此文档，非公开文档表示只对本房间
		$postdata['serial'] = 251401856; //必填 房间号
		$postdata['conversion'] = 1; //必填 是否转换 
		$postdata['serial'] = $_REQUEST["serial"];
		$postdata['sender'] = $_REQUEST["sender"];

		$myfile = 'sss.pptx';
		$urltext = "D:/file/sss.pptx";
		$download = "D:/file2/";   //你的服务器地址
		if($urltext){
			$contents = file_get_contents($urltext);
			//var_dump($contents);
			$filesize=strlen($contents);
			$newfname = $download. $myfile;
			//echo $newfname;
			file_put_contents($newfname , $contents);
		}
		$postdata['filedata'] = '@'.$download.'/'.$myfile;
		//$postdata['filedata'] = '@'.$urltext;  本地服务器测试可以直接使用这个,表示你的文件已经在服务器上
    	$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
    }
	//房间关联文档 返回4105没找到fileidarr字段
	public function ex_roombindfile()
	{
		$url = "http://127.0.0.1/WebAPI/roombindfile/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['serial'] = 251401856; //必填 房间号
		$postdata['fileidarr'] = '12'; //必填 文件id组，文件id数组

		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}
	//获取房间在线用户数 
	public function ex_roomonlinenum()
	{
		$url = "http://127.0.0.1/WebAPI/roomonlinenum/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['serial'] = 531150968; //选填 房间号 如果填写就表示获取某个房间的在线人数，如果不填就表示获取全部房间的在线人数
		$postdata['type'] = 1; //选填 参加用户类型 0: 当前在线人数  1：登录人数

		$resultdata = curl_post($url,$postdata); 
		echo($resultdata);
	}
	//获取房间用户登入登出情况  
	public function ex_getlogininfo()
	{
		$url = "http://127.0.0.1/WebAPI/getlogininfo/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['serial'] = 531150968; //必填 房间号

		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}
	//获取房间当前在线用户信息  返回-1
	public function ex_getonlineuser()
	{
		$url = "http://127.0.0.1/WebAPI/getonlineuser/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['serial'] = 531150968; //必填 房间号

		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}
	//设置房间流
	public function ex_setstream()
	{
		$url = "http://127.0.0.1/WebAPI/setstream/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['serial'] = 531150968; //必填 房间号 
		$postdata['streamid'] = 2000000010; //必填 流id 取值范围： 2000000000 - 2099999999
		$postdata['name'] = 'xiaoming'; //必填 房间中的显示名 

		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}
	//获取房间流
	public function ex_getstream()
	{
		$url = "http://127.0.0.1/WebAPI/getstream/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['serial'] = 531150968; //必填 房间号 
		
		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}
	//删除房间流 
	public function ex_deletestream()
	{
		$url = "http://127.0.0.1/WebAPI/deletestream/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['serial'] = 531150968; //必填 房间号 
		$postdata['streamid'] = 2000000010; //必填 流id 取值范围： 2000000000 - 2099999999

		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}
	//房间中显示url
	public function ex_roomrelaurl()
	{
		$url = "http://127.0.0.1/WebAPI/roomrelaurl/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['serial'] = 531150968; //必填 房间号 
		$postdata['linkname'] = 'admin'; //必填 关联名
		$postdata['linkurl'] = 'http://127.0.0.1/WebAPI/roomrelaurl'; //必填 关联url

		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}

	//2.登录部分
	//获取房间登录地址（服务器端调用）
	public function ex_createloginkey()
	{
		$url = "http://127.0.0.1/WebAPI/createloginkey/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['serial'] = 531150968; //必填 房间号 
		$postdata['nickname'] = 'admin'; //必填 昵称 (昵称如果是中文需要进行UTF8编码，可使用urlencode)
		$postdata['usertype'] = 1; //选填 用户类型 0是普通交互用户，1是主席，2是旁听用户(usertype优先级比密码高)
		$postdata['password'] = '123456'; //房间密码 如果房间（PasswordRequired=1）那么可输入相应密码
		$postdata['invisibleuser'] = 0; //选填 用户是否隐身 1表示隐身， 0表示不隐身

		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}
	//登录房间(用户浏览器访问)
	public function ex_loginroom()
	{
		$url = "http://127.0.0.1/WebAPI/loginroom/";
		$postdata['loginkey'] = 'fa59298dae4f132297d31800d0cfcfdd05c78e22';  //必填 登录key 来自 登录房间（服务器）返回值，
		$postdata['serial'] = 277340593; //必填 房间号 

		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}
	//创建以及加入房间；直接进入房间  
	public function ex_entry()
	{
		$url = "http://127.0.0.1/WebAPI/entry/";
		//$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['serial'] = 545505353; //必填 房间号 非0开始的数字串， 请保证房间号唯一
		$postdata['roomname'] = 'text'; //选填 房间名
		$str = "崔建佳（公主坟测试）";
		$postdata['username'] = urlencode($str); //必填 用户名 用户在房间中显示的名称；使用UTF8编码，特殊字符需使用urlencode转义
		$postdata['usertype'] = 2; //必填，0：主讲(老师 )  1：助教    2: 学员   3：直播用户  4:巡检员
		$postdata['pid'] = 0; //选填, 第三方系统的用户id；默认值为0
		$time = gmmktime(); //当前时间戳
		$postdata['ts'] = $time; //必填，当前GMT时间戳，int格式
		$postdata['auth'] = '5NIWjlgmvqwbt494'; //必填，auth值为MD5(key + ts + serial + usertype)其中key为双方协商的接口密钥：默认值为：5NIWjlgmvqwbt494 
		//$postdata['chairmanpwd'] = '123456'; //选填 主席密码 默认值为0。格式为：128位AES加密串，加密密钥默认为5NIWjlgmvqwbt494
		$postdata['passwordrequired'] = 1; //选填 房间是否需要普通密码 0:否、1:是
		$postdata['userpassword'] = 'b2bc8b4adcf954055bc1c79379157992'; //选填 房间普通用户密码 passwordrequired = 1 时必填(4位以上)。普通用户密码；默认值为0。格式为：128位AES加密串，加密密钥默认为5NIWjlgmvqwbt494
		$postdata['sidelineuserpwd'] = '0'; //直播用密码 选填, 直播用户密码；默认值为0。格式为：128位AES加密串，加密密钥默认为5NIWjlgmvqwbt494
		$postdata['logintype'] = 0; //选填 登录方式 0:客户端   1：表示falsh登录2：表示自动选择，如果安装了客户端，则启动客户端，否则使用flash  
		$postdata['domain'] = 'www'; //公司域名  
		$postdata['invisibleuser'] = 1; //选填 用户是否隐身 1表示隐身， 0表示不隐身
		$postdata['donotauth'] = 1; //选填 用户是否隐身 1表示隐身， 0表示不隐身
		var_dump($postdata);
		//$this->setRequestProperty("contentType", "UTF-8");
		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}

	//2.4 登录房间(直接启动PC客户端或移动app进入房间)
	public function ex_directloginroom()
	{
		
	}
	//3.用户部分
	//创建用户
	public function ex_usercreate()
	{
		$url = "http://127.0.0.1/WebAPI/usercreate/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['account'] = 'xiaoming'; //必填 用户账号 （保证唯一）
		$postdata['userpwd'] = '123456'; //必填 用户面 
		$postdata['firstname'] = 'xiaoming'; //必填 姓名 

		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}
	//修改用户
	public function ex_usermodify()
	{
		$url = "http://127.0.0.1/WebAPI/usermodify/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['account'] = 'xiaoming'; //必填 用户账号 （保证唯一）
		$postdata['userpwd'] = '123456'; //必填 用户面 
		$postdata['firstname'] = 'xiaoming'; //必填 姓名 

		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}
	//删除用户
	public function ex_userdelete()
	{
		$url = "http://127.0.0.1/WebAPI/userdelete/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['account'] = 'xiaoming'; //必填 用户账号 （保证唯一）

		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}
	//获取用户
	public function ex_getuser()
	{
		$url = "http://127.0.0.1/WebAPI/getuser/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id  authkey
		$postdata['account'] = 'xiaoming'; //必填 用户账号 （保证唯一）

		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}

	//4.组部分
	//创建组 
	public function ex_groupcreate()
	{
		$url = "http://127.0.0.1/WebAPI/groupcreate/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['groupname'] = 'zuming'; //必填 组名 
		$postdata['userarr'] = 'xiaoming1,xiaoming2'; //选填 组中的成员 账号数组

		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}
	//修改组
	public function ex_groupmodify()
	{
		$url = "http://127.0.0.1/WebAPI/groupmodify/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['groupid'] = 125654; //必填 组id 
		$postdata['groupname'] = 'zuming'; //必填 组名

		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}
	//增加组中成员
	public function ex_addgroupuser()
	{
		$url = "http://127.0.0.1/WebAPI/addgroupuser/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['groupid'] = 125654; //必填 组id 
		$postdata['userarr'] = 'xiaoming,admin'; //组中的成员 账号数组

		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}
	//删除组成员
	public function ex_deletegroupuser()
	{
		$url = "http://127.0.0.1/WebAPI/deletegroupuser/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['groupid'] = 125654; //必填 组id 
		$postdata['userarr'] = 'xiaoming'; //选填 组中的成员 账号数组

		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}
	//获取组
	public function ex_getgroup()
	{
		$url = "http://127.0.0.1/WebAPI/getgroup/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['groupid'] = 125654; //必填 组id 
		
		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}
	//删除组
	public function ex_groupdelete()
	{
		$url = "http://127.0.0.1/WebAPI/groupdelete/";
		$postdata['key'] = '5NIWjlgmvqwbt494';  //必填 企业id authkey
		$postdata['groupid'] = 125654; //必填 组id 
		
		$resultdata = $this->curl_post($url,$postdata); 
		echo($resultdata);
	}
	//aes 加密，解密
	public function ex_aestest()
    {
    	//$ckey = '2NIZjlgmXqwbW016';0bb147de3666563b588430ebd78d18bf
        //$chairmansourcepwd = 'zx8380000';
        $ckey = I('key');
        $chairmansourcepwd = I('pwd');
        $ChairmanPWD = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $ckey, $chairmansourcepwd, MCRYPT_MODE_ECB);
		var_dump('encrypt:');
        var_dump(bin2hex($ChairmanPWD));
        $bin_str = pack("H*" , bin2hex($ChairmanPWD)); 
        $orgtext = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $ckey, $bin_str, MCRYPT_MODE_ECB));
        var_dump('decrypt:');
        var_dump($orgtext);
    }
}
?>
